import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:oktoast/oktoast.dart';
import 'package:wan_android_flutter/common/base/base_page.dart';
import 'package:wan_android_flutter/common/routes/route_manager.dart';
import 'package:wan_android_flutter/generated/locales.g.dart';
import 'package:wan_android_flutter/res/assets_res.dart';

import '../../common/base/custom_app_bar.dart';
import '../../common/resources/spacing.dart';
import 'search_logic.dart';

class SearchPage extends BasePage<SearchLogic> {
  SearchPage({super.key});

  @override
  PreferredSizeWidget? buildAppBar(BuildContext context) {
    return CustomAppBar(
        barHeight: 52,
        child: Container(
          color: colorData.textBlue,
          padding: EdgeInsets.only(left: 16, right: 16, top: MediaQuery.of(context).padding.top),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              InkWell(
                onTap: () {
                  Get.back();
                },
                child: Image.asset(
                  AssetsRes.BACK,
                  width: 25,
                  height: 25,
                  color: Colors.white,
                ),
              ),
              Spacing.hSpacing10,
              Expanded(
                  child: TextField(
                decoration: InputDecoration(
                  border: InputBorder.none,
                  hintText: LocaleKeys.search_hint.tr,
                  hintStyle: const TextStyle(color: Colors.white, fontSize: 18),
                ),
                focusNode: logic.focusNode,
                style: const TextStyle(color: Colors.white, fontSize: 18),
                textInputAction: TextInputAction.search,
                onSubmitted: (text) {
                  if (text.isEmpty) {
                    showToast(LocaleKeys.search_hint.tr);
                    return;
                  }
                  Get.toNamed(RouteManager.searchResultPage, arguments: text);
                },
              ))
            ],
          ),
        ));
  }

  @override
  Widget buildContent(BuildContext context) {
    return Container(
      color: colorData.bgWhite,
    );
  }
}
